﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Windows;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using YCAAUTOFSAB;
using INTEX.DataBase;
namespace WPFExcelReport
{
    public partial class YCAAUTOFSABData
    { 
 
        public DataSet Convert2ABKOPF(DataRow dwData)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "ABKOPF_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetExt.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "ABKOPF";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim().Trim() == "ABKOPF"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwData);
            }
            tbIntex.Rows.Add(dwIntex);
            EventDispatcher.Instance.RaiseStatus("转换生产单头AB04:" + dwData["ABPAUFKRS"].ToString() + "-" + dwData["ABPAUFLFD"].ToString(), StatusEventType.RunningProgress);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2ABPOSFS(DataRow dwData)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "ICC_ABPOSFS_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetExt.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "ICC_ABPOSFS";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim().Trim() == "ICC_ABPOSFS"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwData);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        
        public DataSet Convert2ABPOS_EXT(DataRow dwData)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "ABPOS_EXT_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetExt.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "ABPOS_EXT";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim().Trim() == "ABPOS_EXT"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwData);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2ABPR(DataRow dwData)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "ABPR_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetExt.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "ABPR";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim().Trim() == "ABPR"
                        select dwMap;
            EventDispatcher.Instance.RaiseStatus("转换ABPR:" + dwData["ABPAUFKRS"].ToString() + "-" + dwData["ABPAUFLFD"].ToString() + "-" + dwData["ABPAUFPOS"].ToString(), StatusEventType.RunningProgress);
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwData);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2ABFOLGE(DataRow dwABPOS)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            OracleCommand or1;
            DataRow dwLocal;
            try
            {
                //从Sample中将默认值代替，然后用ABPOS的值进行创建  
                if (!SetExt.Tables.Contains("ABPOS_NEW"))
                {
                    DataTable abpnew = dwABPOS.Table.Clone();
                    abpnew.TableName = "ABPOS_NEW";
                    SetExt.Merge(abpnew);
                }
                else
                {
                    SetExt.Tables["ABPOS_NEW"].Clear();
                }
                DataRow dwABPNEW = SetExt.Tables["ABPOS_NEW"].NewRow();
                dwABPNEW.ItemArray = dwABPOS.ItemArray;
                SetExt.Tables["ABPOS_NEW"].Rows.Add(dwABPNEW);
                #region============APFOLGE=========================
                string pKRS=dwABPOS["ABPANRKR"].ToString();
                string pLFD = dwABPOS["ABPALFDNR"].ToString();
                DataSet SABFOLGE = INTEXDBC.QueryAPFOLGE("00", pKRS, pLFD);
                if (SABFOLGE.Tables.Count == 0)
                    return setReturn;
                DataTable TSABFOLGE = SABFOLGE.Tables[0];
                TSABFOLGE.TableName = "APFOLGE";
                #endregion
                DataSet setTemp = new DataSet();
                string mapID = "ABFOLGE_MAP";
                DataTable tbMapID = new DataTable();
                tbMapID = SetExt.Tables[mapID];
                DataTable tbIntex = new DataTable();
                tbIntex.TableName = "ABFOLGE";
                DataRow dwIntex = tbIntex.NewRow();
                var query = from dwMap in tbMapID.AsEnumerable()
                            where dwMap["FILE"].ToString().Trim().Trim() == "ABFOLGE"
                            select dwMap;
                EventDispatcher.Instance.RaiseStatus("转换ABFOLGE:", StatusEventType.RunningProgress);
                foreach (DataRow rwABFOLGE in TSABFOLGE.Rows)
                {
                    foreach (DataRow dwRule in query)
                    {
                        Convert2Intex.GetCovnertValue(ref dwIntex, dwRule, rwABFOLGE);
                    }
                    tbIntex.Rows.Add(dwIntex);
                    dwIntex = tbIntex.NewRow();
                }
                setReturn.Merge(tbIntex);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet Convert2ABAUFM(DataRow dwData)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "ABAUFM_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetExt.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "ABAUFM";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim().Trim() == "ABAUFM"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwData);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2FDECKB(DataRow dwData)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "FDECKB_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetExt.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "FDECK";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim().Trim() == "FDECK"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwData);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2FDECKZ(DataRow dwData)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "FDECKZ_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetExt.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "FDECK";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim().Trim() == "FDECK"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwData);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2MDECK(DataRow dwData)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "MDECK_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetExt.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "MDECK";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim().Trim() == "MDECK"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwData);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2WDECK(DataRow dwData)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WDECK_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetExt.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "WDECK";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim().Trim() == "WDECK"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwData);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2GAAUF733(DataRow dwData)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "GAAUF733_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetExt.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "GAAUF";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim().Trim() == "GAAUF"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwData);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
    }
}
